package cmd

import (
	"Yoj/internal/controller/Code"
	"Yoj/internal/controller/Problem"
	"Yoj/internal/controller/User"
	"Yoj/internal/controller/authmiddleware"
	"context"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
)

var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			s := g.Server()
			s.Group("/", func(group *ghttp.RouterGroup) {
				group.Middleware(ghttp.MiddlewareHandlerResponse)
				group.Bind(
					User.NewVerify(), // Login
					User.NewRegist(), // Register
				)
				group.Group("/", func(group *ghttp.RouterGroup) {
					group.Middleware(authmiddleware.Auther)
					group.Bind(
						Code.NewFileSubmit(), // Submit code file
					)
				})
				group.Group("/", func(group *ghttp.RouterGroup) {
					group.Middleware(authmiddleware.AdminAuther)
					group.Bind(
						Problem.NewCreate(), // Create problem
						Problem.NewModify(), // Modify problem
					)
				})
			})
			s.Run()
			return nil
		},
	}
)
